package io.kiki.stack.netty.invoker;

import io.kiki.stack.netty.command.Command;
import io.netty.util.Timeout;

import java.net.InetSocketAddress;

public interface Future {

    Command waitResponse(final long timeoutMillis) throws InterruptedException;

    Command waitResponse() throws InterruptedException;

    /**
     * Create a remoting command response when Channel closed
     */
    Command createChannelClosedResponse(InetSocketAddress responseHost);

    void putResponse(final Command response);

    int id();

    void executeInvokeCallback();

    /**
     * Asynchronous execute the callback abnormally.
     */
    void tryAsyncExecuteInvokeCallbackAbnormally();

    /**
     * Get the cause of exception of the future.
     *
     * @return the cause
     */
    Throwable getCause();

    /**
     * Set the cause if exception caught.
     */
    void setCause(Throwable cause);

    /**
     * Get the application callback of the future.
     *
     * @return get invoke callback
     */
    Callback getInvokeCallback();

    /**
     * Add timeout for the future.
     */
    void addTimeout(Timeout timeout);

    /**
     * Cancel the timeout.
     */
    void cancelTimeout();

    /**
     * Whether the future is done.
     *
     * @return true if the future is done
     */
    boolean isDone();

    /**
     * Get application classloader.
     *
     * @return application classloader
     */
    ClassLoader getAppClassLoader();


    RequestContext getInvokeContext();

    void setInvokeContext(RequestContext requestContext);
}
